﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Data;
using System.Data;
using ClassLibrary.Entity;

namespace ClassLibrary.DAO
{
    public class TblParentMenuDAO
    {
        private DBService _db = null;

        public TblParentMenuDAO(String connectionString)
        {
            _db = new DBService(connectionString);
        }

        public DataTable InUpParentMenu(TblParentMenu parentMenu, int mode)
        {
            DataTable flag = null;
            try
            {
                flag = _db.ExeSP_DataTable("sp_TblParentMenu_InsUp",
                    new string[] { "@IDMenu_Parent", "@MenuParentName", "@MenuDescription", "@Mode" },
                    new object[] { parentMenu.IDMenu_Parent, parentMenu.MenuParentName, parentMenu.MenuDescription, mode }, CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return flag;
        }
        public DataTable GetMenuParent()
        {
            DataTable Menu = null;
            try
            {
                Menu = _db.ExeSP_DataTable("select * from TblParentMenu", false, CommandType.Text);

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return Menu;
        }

        public DataTable GetMenu_ParentByID(int IDMenuParent)
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("select * from TblParentMenu where IDMenu_Parent = @IDMenu_Parent",
                    new string[] { "@IDMenu_Parent" },
                    new object[] { IDMenuParent },
                    CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public TblParentMenu GetMenuParentByID(int IDMenuParent)
        {
            TblParentMenu menuParent = new TblParentMenu();
            try
            {
                DataTable Menu = null;
                Menu = _db.ExeSP_DataTable("select * from TblParentMenu where IDMenu_Parent = @IDMenu_Parent",
                    new string[] { "@IDMenu_Parent" },
                    new object[]{IDMenuParent}
                        , CommandType.Text);
                foreach (DataRow dr in Menu.Rows)
                {
                    menuParent.IDMenu_Parent = IDMenuParent;
                    menuParent.MenuDescription = dr["MenuDescription"].ToString();
                    menuParent.MenuParentName = dr["MenuParentName"].ToString();

                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return menuParent;
        }

        public bool DeleteParentMenu(TblParentMenu parentMenu)
        {
            bool flag = false;
            try
            {
                _db.ExeSP_NonQuery("delete TblParentMenu where IDMenu_Parent = @IDMenu_Parent",
                    new string[] { "@IDMenu_Parent" },
                    new object[] { parentMenu.IDMenu_Parent },
                    CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return flag;
        }
    }
}
